<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <link href="./css/rDBLogin.css" rel="stylesheet" />
    <title>用户登录</title>
</head>
<body>
<!-- 主题切换按钮 -->
<button onclick="toggleTheme()" class="theme-toggle" style="
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 10px 15px;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
">
    🌙/☀️
</button>
<form action="login" method="post">
    <h2>用户登录</h2>
    <%-- 错误提示 --%>
    <c:if test="${not empty sessionScope.errorMessage}">
        <div class="error-message">
                ${sessionScope.errorMessage}
        </div>
        <c:remove var="errorMessage" scope="session"/>
    </c:if>
    <label>
        学号/工号：
        <input type="text" name="id" required>
    </label>
    <label>
        密码：
        <input type="password" name="password" required>
    </label>
    <input type="submit" value="登录">
    <a href="rDBRegister.jsp">注册新账号</a>
</form>
</body>
</html>
<script>
    // 初始化主题
    function initTheme() {
        const savedTheme = localStorage.getItem('theme') || 'dark';
        const isLight = savedTheme === 'light';
        document.body.classList.toggle('light-mode', isLight);
        document.querySelector('.theme-toggle').textContent = isLight ? '☀️' : '🌙';
    }

    // 切换主题
    function toggleTheme() {
        const body = document.body;
        const isLight = !body.classList.contains('light-mode');
        body.classList.toggle('light-mode');
        localStorage.setItem('theme', isLight ? 'light' : 'dark');
        document.querySelector('.theme-toggle').textContent = isLight ? '☀️' : '🌙';
    }

    // 页面加载时初始化
    window.addEventListener('load', initTheme);
</script>